<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<!-- 组件js，和业务不相关的 -->
<script src="./tio.js"></script>


<!-- 和业务相关的js，业务需要修改 -->
<script src="./DemoHandler.js"></script>

<script>
    var socket;
    var handler = new DemoHandler()
    // 判断当前浏览器是否支持webSocket编程
    if(window.WebSocket){
        var queryString = 'userId=test001'

        socket = new tio.ws("wss", "rjapi.lvseguanjia.cn/tim", "443", queryString, "", handler, 5000, 1000, 'blob');
        socket.connect()
    }else {
        alert("当年浏览器不支持webSocket")
    }

    function send(message) {
        if(!window.socket){
            return;
        }
        if(socket.ws.readyState == WebSocket.OPEN) {
            socket.send(null, "test001", "zhoumingx", "TEXT", message);
        } else {
            alert("连接未开启");
        }
    }
</script>
<body>
<form onsubmit="return false">
    <label>
        <textarea name="message" style="height: 300px; width: 300px"></textarea>
    </label>
    <input type="button" value="发送消息" onclick="send(this.form.message.value)">
    <label>
        <textarea id="responseText" style="height: 300px; width: 300px"></textarea>
    </label>
    <input type="button" value="清空内容"
           onclick="document.getElementById('responseText').value=''">
</form>
</body>
</html>